/*
 *  basic_string.h
 *  FrostOS
 *
 *  Created by bluechill on 12/5/09.
 *  Copyright 2009 SecurityOverride. All rights reserved.
 *
 */
#ifndef basic_string_H
#define basic_string_H

#include <size_t.h>

namespace std {

template <class T>
class basic_string {
public:
	char* characters;
	
		//Initalizers
	basic_string()
	{
		characters = "";
	}
		//basic_string ( const basic_string& str, size_t pos, size_t n = npos );
	basic_string ( const char * s, size_t n );
	basic_string ( size_t n, char c );
	
	basic_string(const basic_string& str)
	{
		*this = str;
	}
	
	basic_string(char *s)
	{
		characters = s;
	}
	
		//templates
	template<class InputIterator> basic_string (InputIterator begin, InputIterator end);
	template <class InputIterator>
	
		//Operators
	basic_string<T>& operator= ( const basic_string<T>& str )
	{
		this = str;
		return *this;
	}
	
	basic_string<T>& operator= ( const char* s )
	{
		characters = s;
		return *this;
	}
	
	basic_string<T>& operator= ( char c )
	{
		characters = c;
		return *this;
	}
	
	bool operator== ( const basic_string<T>& lhs);
	bool operator== ( const char* lhs);
	
	bool operator!= ( const basic_string<T>& lhs);
	bool operator!= ( const char* lhs);
	
	basic_string<T>& operator+= ( const basic_string<T>& str);
	basic_string<T>& operator+= ( const char* s );
	basic_string<T>& operator+= ( char c );
	
	basic_string<T> operator+ (const basic_string<T>& lhs);
	basic_string<T> operator+ (const char* lhs);
	basic_string<T> operator+ (char lhs);
	
		//Iterators
		//TODO: Define ITERATORS
	/*
	iterator begin();
	const_iterator begin() const;
	iterator end();
	const_iterator end() const;
	reverse_iterator rbegin();
	const_reverse_iterator rbegin() const;
	reverse_iterator rend();
	const_reverse_iterator rend() const;
	 */
	
		//size_t
		//template <class T>
	size_t size()
	{
		return intstrlen(characters);
	}
	size_t length();
	size_t max_size ( );
		// TODO: Fix size_t stuff and appends and finish string functions
	/*
	size_t copy ( char* s, size_t n, size_t pos = 0) const;
	size_t capacity ( ) const;
	size_t find ( const basic_string& str, size_t pos = 0 ) const;
	size_t find ( const char* s, size_t pos, size_t n ) const;
	size_t find ( const char* s, size_t pos = 0 ) const;
	size_t find ( char c, size_t pos = 0 ) const;
	size_t rfind ( const basic_string& str, size_t pos = npos ) const;
	size_t rfind ( const char* s, size_t pos, size_t n ) const;
	size_t rfind ( const char* s, size_t pos = npos ) const;
	size_t rfind ( char c, size_t pos = npos ) const;
	size_t find_first_of ( const basic_string& str, size_t pos = 0 ) const;
	size_t find_first_of ( const char* s, size_t pos, size_t n ) const;
	size_t find_first_of ( const char* s, size_t pos = 0 ) const;
	size_t find_first_of ( char c, size_t pos = 0 ) const;
	size_t find_last_of ( const basic_string& str, size_t pos = npos ) const;
	size_t find_last_of ( const char* s, size_t pos, size_t n ) const;
	size_t find_last_of ( const char* s, size_t pos = npos ) const;
	size_t find_last_of ( char c, size_t pos = npos ) const;
	size_t find_first_not_of ( const basic_string& str, size_t pos = 0 ) const;
	size_t find_first_not_of ( const char* s, size_t pos, size_t n ) const;
	size_t find_first_not_of ( const char* s, size_t pos = 0 ) const;
	size_t find_first_not_of ( char c, size_t pos = 0 ) const;
	size_t find_last_not_of ( const basic_string& str, size_t pos = npos ) const;
	size_t find_last_not_of ( const char* s, size_t pos, size_t n ) const;
	size_t find_last_not_of ( const char* s, size_t pos = npos ) const;
	size_t find_last_not_of ( char c, size_t pos = npos ) const;
	
	void resize ( size_t n, char c );
	void resize ( size_t n );
	void reserve ( size_t res_arg=0 );
	
		//basic_string specifics
	basic_string& append ( const basic_string& str );
	basic_string& append ( const basic_string& str, size_t pos, size_t n );
	basic_string& append ( const char* s, size_t n );
	basic_string& append ( const char* s );
	basic_string& append ( size_t n, char c );
	basic_string& append ( InputIterator first, InputIterator last );
	basic_string& assign ( const basic_string& str );
	basic_string& assign ( const basic_string& str, size_t pos, size_t n );
	basic_string& assign ( const char* s, size_t n );
	basic_string& assign ( const char* s );
	basic_string& assign ( size_t n, char c );
	
	basic_string& assign ( InputIterator first, InputIterator last );
	basic_string& insert ( size_t pos1, const basic_string& str );
	basic_string& insert ( size_t pos1, const basic_string& str, size_t pos2, size_t n );
	basic_string& insert ( size_t pos1, const char* s, size_t n);
	basic_string& insert ( size_t pos1, const char* s );
	basic_string& insert ( size_t pos1, size_t n, char c );
	
	basic_string& erase ( size_t pos = 0, size_t n = npos );
	
	basic_string& replace ( size_t pos1, size_t n1,   const basic_string& str );
	basic_string& replace ( iterator i1, iterator i2, const basic_string& str );
	
	basic_string& replace ( size_t pos1, size_t n1, const basic_string& str, size_t pos2, size_t n2 );
	
	basic_string& replace ( size_t pos1, size_t n1,   const char* s, size_t n2 );
	basic_string& replace ( iterator i1, iterator i2, const char* s, size_t n2 );
	
	basic_string& replace ( size_t pos1, size_t n1,   const char* s );
	basic_string& replace ( iterator i1, iterator i2, const char* s );
	
	basic_string& replace ( size_t pos1, size_t n1,   size_t n2, char c );
	basic_string& replace ( iterator i1, iterator i2, size_t n2, char c );
	
	basic_string& replace ( iterator i1, iterator i2, InputIterator j1, InputIterator j2 );
	
	basic_string substr ( size_t pos = 0, size_t n = npos ) const;
	*/
	void clear();
	bool empty ( ) const;
	const char& operator[] ( size_t pos ) const;
		//template <class T>
	char& operator[] ( unsigned i )
	{
		return characters[i];
	}
	const char& at ( size_t pos ) const;
    char& at ( size_t pos );
	
	
	
	
	void push_back ( char c );
		//TODO: Add this stuff
	/*
	iterator insert ( iterator p, char c );
    void insert ( iterator p, size_t n, char c );
	
    void insert ( iterator p, InputIterator first, InputIterator last );
	
	iterator erase ( iterator position );
	iterator erase ( iterator first, iterator last );
	
	
	
	
	
	void swap ( basic_string& str );
	const char* c_str ( ) const;
	const char* data() const;
	allocator<char> get_allocator( ) const;
	
	
	int compare ( const basic_string& str ) const;
	int compare ( const char* s ) const;
	int compare ( size_t pos1, size_t n1, const basic_string& str ) const;
	int compare ( size_t pos1, size_t n1, const char* s) const;
	int compare ( size_t pos1, size_t n1, const basic_string& str, size_t pos2, size_t n2 ) const;
	int compare ( size_t pos1, size_t n1, const char* s, size_t n2) const;
	
	void swap ( basic_string& lhs, basic_string& rhs);
	 */
private:
	size_t intstrlen(const char* s)
	{
		size_t len = 0;
	
	    for (;*s != '\0';*s++)
	    {
	    	len++;
	    }
	
		return len;
	}
};

typedef basic_string<char> string;

};
#endif
